package goleetcode

func alternatingSubarray(nums []int) int {
	res := -1
	n := len(nums)
	for idx1 := 0; idx1 < n; idx1++ {
		for i := idx1 + 1; i < n; i++ {
			length := i - idx1 + 1
			if nums[i] - nums[idx1] == (length - 1) % 2 {
				res = max(res, length)
			} else {
				break
			}
		}
	}
	return res
}